package com.suning.sawp.service.impl.dao.mainpushnew;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.suning.framework.dal.client.DalClient;
import com.suning.sawp.intf.dao.mainpushnew.MainPushTaskHqViewDao;
import com.suning.sawp.vo.mainpushnew.BiAreaTaskProgressVo;
import com.suning.sawp.vo.mainpushnew.BiHqTaskProgressVo;
import com.suning.sawp.vo.mainpushnew.BiModelProgressVo;

/**
 * 
 * 总部主推任务查看dao实现<br>
 *
 * @author 14060886 祝翔龙
 */
@Repository
public class MainPushTaskHqViewDaoImpl implements MainPushTaskHqViewDao {

    @Resource
    private DalClient dalClient;

    @Override
    public BiHqTaskProgressVo selectHqTaskProgress(Long hqTaskId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hqTaskId", hqTaskId);
        return dalClient.queryForObject("mainPushHqView.selectHqTaskProgress", params, BiHqTaskProgressVo.class);
    }

    @Override
    public Integer countAreaTaskProgress(Long hqTaskId, String queryParam) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hqTaskId", hqTaskId);
        if(isChinese(queryParam)){
            params.put("disName", queryParam);
        }else{
            params.put("disCode", queryParam);
        }
        return dalClient.queryForObject("mainPushHqView.countAreaTaskProgress", params, Integer.class);
    }

    @Override
    public List<BiAreaTaskProgressVo> selectAreaTaskProgress(Long hqTaskId, String queryParam, Map<String, Integer> pageParams) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.putAll(pageParams);
        params.put("hqTaskId", hqTaskId);
        if(isChinese(queryParam)){
            params.put("disName", queryParam);
        }else{
            params.put("disCode", queryParam);
        }
        return dalClient.queryForList("mainPushHqView.selectAreaTaskProgress", params, BiAreaTaskProgressVo.class);
    }

    @Override
    public List<BiModelProgressVo> selectModelProgress(Long hqTaskId, String disCode) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hqTaskId", hqTaskId);
        params.put("disCode", disCode);
        return dalClient.queryForList("mainPushHqView.selectModelProgress", params, BiModelProgressVo.class);
    }

    @Override
    public BigDecimal selectCateSaleAmountByCode(String cateCode, String month, String disCode) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("cateCode", cateCode);
        params.put("month", month);
        params.put("disCode", disCode);
        return dalClient.queryForObject("mainPushHqView.selectCateSaleAmountByCode", params, BigDecimal.class);
    }

    @Override
    public List<BiAreaTaskProgressVo> selectTotalAreaTaskProgress(Long hqTaskId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hqTaskId", hqTaskId);
        return dalClient.queryForList("mainPushHqView.selectTotalAreaTaskProgress", params, BiAreaTaskProgressVo.class);
    }

    @Override
    public Integer selectTargetNumByDisAndType(Long hqTaskId, String disCode, String taskType) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("hqTaskId", hqTaskId);
        params.put("disCode", disCode);
        params.put("taskType", taskType);
        return dalClient.queryForObject("mainPushHqView.selectTargetNumByDisAndType", params, Integer.class);
    }

    @Override
    public List<String> queryCommCdsByCateCode(String cateCode, String month) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("cateCode", cateCode);
        paramMap.put("month", month);
        return dalClient.queryForList("mainPushHqView.queryCommCdsByCateCd", paramMap, String.class);
    }
    
    private boolean isChinese(String str) {  
        String reg = "([\u4e00-\u9fa5]+)";
        Pattern p = Pattern.compile(reg);  
        return p.matcher(str).find();
    }  
   
}
